package com.mj.mafeed.service;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;

import android.content.Context;

import com.mj.mafeed.bean.ShippingMethodJSON;
import com.mj.mafeed.dao.ShippingMethodDao;

/**
 * 配送方式
 * @author zhaominglei
 * @date 2014-12-23
 * 
 */
public class ShippingMethodService {
	private ShippingMethodDao shippingMethodDao = new ShippingMethodDao();
	/**
	 * 同步配送方式
	 */
	public void syncShippingMethod(Context context) {
		int count = shippingMethodDao.getCount(context);
		if (count > 0) {
			return;
		}
		InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("config/feed_shipping_method.sql");
		BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
		String sql = null;
		try {
			while((sql = br.readLine()) != null) {
				shippingMethodDao.save(context, sql);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 获取所有配送方式
	 */
	public List<ShippingMethodJSON> getAll(Context context) {
		return shippingMethodDao.getAll(context);
	}
}
